<?php

declare(strict_types=1);

namespace App\Model;


/**
 * @property int $id ID
 * @property int $catid 分类ID
 * @property string $title 标题
 * @property string $thumb 缩略图
 * @property string $image_list 图片列表
 * @property string $keywords 关键词
 * @property string $description 简介
 * @property int $hits 点击量
 * @property int $praise 点赞量
 * @property int $collect 收藏
 * @property int $is_link 是否外链
 * @property int $is_recommend 是否推荐
 * @property string $tags 标签
 * @property int $source 来源 0-未知 1-后台发布 2-同步 3-接口采集入库
 * @property int $author_id 作者ID
 * @property int $add_time 发布时间
 * @property int $edit_time 修改时间
 * @property int $sync_time 同步时间
 * @property-read null|Category $category 
 * @property-read null|ArticleAuthor $author 
 * @property-read null|ArticleContent $content 
 */
class Article extends Model
{
    /**
     * The table associated with the model.
     */
    protected ?string $table = 'article';

    /**
     * The attributes that are mass assignable.
     */
    protected array $fillable = ['id', 'catid', 'title', 'thumb', 'image_list', 'keywords', 'description', 'hits', 'praise', 'collect', 'is_link', 'is_recommend', 'tags', 'source', 'author_id', 'add_time', 'edit_time', 'sync_time'];

    /**
     * The attributes that should be cast to native types.
     */
    protected array $casts = ['id' => 'integer', 'catid' => 'integer', 'hits' => 'integer', 'praise' => 'integer', 'collect' => 'integer', 'is_link' => 'integer', 'is_recommend' => 'integer', 'source' => 'integer', 'author_id' => 'integer', 'add_time' => 'integer', 'edit_time' => 'integer', 'sync_time' => 'integer'];

    public function category()
    {
        return $this->hasOne(Category::class, 'id', 'catid')->select(['id', 'catname', 'game_id', 'sport_id']);
    }

    public function author()
    {
        return $this->hasOne(ArticleAuthor::class, 'id', 'author_id');
    }

    public function content()
    {
        return $this->hasOne(ArticleContent::class, 'contentid', 'id');
    }
}
